<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>js和CSS配合动画Demo</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
            width: 100vw;
            height: 100vh;
            background-color: #34495e;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        span{
            font-size: 2em;
            display: inline-block;
        }
        .color{
            animation-name: show;
            animation-duration: 1s;
            animation-iteration-count: 2;
            animation-timing-function: linear;
            animation-direction: alternate;
        }
        @keyframes show{
            50%{
                color: #f1c40f;
                transform: scale(2);
            }
            100%{
                color: #e74c3c;
                transform: scale(.5);
            }
        }
    </style>
</head>
<body>
    <div>jimmy.com</div>
</body>
<script>
    /*
        使用...语法 将内容整合成为一个数组
        使用reduce抽离出数组和修改指定的数组数据

        事件监听 有一个 animationend事件 代表的是动画结束以后会执行的事件

        使用append可以实现插入子元素
    */
    let div = document.querySelector('div')
    let text = div.innerHTML
    let arr = [...text]
    console.log(arr)
    arr.reduce((pre,item,index)=>{
        if(pre === index){
            div.innerHTML = ''
        }
        let span = document.createElement('span')
        span.innerHTML = item
        div.append(span)
        span.addEventListener('mouseover',()=>{
            span.classList.add('color')
        })
        span.addEventListener('animationend',()=>{
            span.classList.remove('color')
        })
    },0)
</script>
</html>